#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 200010, INF = 1e14;
int n, a[N];
int get(int x, int y) {
    if (y == 0) return x;
    return x + INF;
}
struct Node {
    int qqq[N], duo[N], quan;
    map<int, int> mp;
    int maxn;
    void all_add(int x) {
        //cout<<"all_add: "<<x<<endl;
        quan += x;
    }
    void modify(int x, int d) {
        //cout<<"modify: "<<x<<" "<<d<<endl;
        d -= duo[x];
        qqq[x] = max(qqq[x], d);
        maxn = max(maxn, qqq[x]);
        mp[a[x]] = max(mp[a[x]], qqq[x]);
    }
    int query() {
        return quan + maxn;
    }
    void init() {
        for (int i = 1; i <= n; i ++ ) qqq[i] = duo[i] = 0;
        quan = maxn = 0;
        mp.clear();
    }
    int query(int x) {
        if (!mp.count(x)) return -INF;
        return quan + mp[x];
    }
}f[2];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i ++ ) cin >> a[i];
    f[0].init(), f[1].init();
    for (int i = 1; i <= n; i ++ )
    {
        int q1 = f[1].query(), q0 = f[0].query();
        int qq1 = f[1].query(a[i]), qq0 = f[0].query(a[i]);
        //cout<<"i = " << i << endl;
        if (a[i] == a[i - 1]) f[0].all_add(a[i]), f[1].all_add(a[i]);
        f[0].duo[i] = f[0].quan, f[1].duo[i] = f[1].quan;
        f[0].qqq[i] -= f[0].duo[i], f[1].qqq[i] -= f[1].duo[i];
        /*
        for (int j = 0; j < i; j ++ )
            for (int k = 0; k < 2; k ++ )
                f[i][j][k] = max(f[i][j][k], f[i - 1][j][k] + (a[i] == a[i - 1] ? a[i] : 0));
        */
        f[0].modify(i - 1, max(q1, qq1 + a[i]) - (a[i] == a[i - 1] ? a[i] : 0));
        f[1].modify(i - 1, max(q0, qq0 + a[i]) - (a[i] == a[i - 1] ? a[i] : 0));
        //for (int j = 0; j < i - 1; j ++ )
        //    for (int k = 0; k < 2; k ++ )
        //    f[i][i - 1][k] = max(f[i][i - 1][k], (a[i] == a[j] ? a[i] : 0) + f[i - 1][j][k ^ 1]);
        //f[0].print();f[1].print();cout<<"--------------------------------------"<<endl;
    }
    int res = 0;
    //for (int i = 1; i <= n; i ++ )
    cout << max(f[0].query(), f[1].query()) << "\n";
}
signed main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;
    cin >> T;
    while (T -- )
        solve();
    return 0;
}
